package com.baiyun.controller.admin;

import com.baiyun.Result.Result;
import com.baiyun.entity.RegisterInfo;
import com.baiyun.entity.User;
import com.baiyun.service.RegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/register")
@RequiredArgsConstructor
@Api(tags = "管理员端——注册管理")
public class RegisterController {

    private final RegisterService registerService;

    /**
     * 注册
     * @param registerInfo
     * @return
     */
    @ApiOperation("注册")
    @PostMapping
    public Result register(@RequestBody RegisterInfo registerInfo) {
        String username = registerInfo.getUsername();
        String password = registerInfo.getPassword();
        String type = registerInfo.getType();
        String telephone = registerInfo.getTelephone();
        if (username == null || password == null || type == null || telephone == null) {
            return Result.error("注册失败");
        }

        registerService.register(username, password, type, telephone);

        return Result.success();
    }
}


